<template>
    <div class="child">
        <h3>子组件1</h3>
        <h4>玩具: {{ toy }}</h4>
        <h4>获得Child2的数据: {{ getSendData }}</h4>
        <button @click="emitter.emit('send-toy',toy)">数据给Child2组件</button>
    </div>
</template>

<script setup lang="ts" name="Child1">
import {ref} from "vue";
import emitter from '@/utils/emitter'
let getSendData = ref('')
// 给emitter绑定send-data事件，回调获取Child2组件传递的数据
emitter.on('send-data',(value:any)=>{
    getSendData.value = value
})
let toy = ref('赛车')

</script>

<style scoped>
    .child{
        background-color: skyblue;
        padding: 10px;
        box-shadow: 0 0 10px black;
        border-radius: 10px;
    }
</style>